/**
  ******************************************************************************
  * @file    WF_ConnectionState.c
  * @author  exatron
  * @version V1.0.0
  * @date    segunda, 22 de dezembro de 2014
  * @brief   Retorna o estado da conexão.
  ******************************************************************************
  * @attention
  *
  *
  ******************************************************************************
  */

/** @addtogroup WF
  * @{
  */

/* Includes ------------------------------------------------------------------*/
#include <common.h>

/* External functions --------------------------------------------------------*/

/** @defgroup WF_Functions
  * @{
  */

/**
  * @brief  Retorna o estado da conexão.
  * @param  Nenhum
  * @retval Devolve pela serial ConnectionStatus_t
  */
void WF_ConnectionState(void)
{
	/* Server para STA */
	if(aux_GetConnectionState() == Status_ConnectionConnecting)
	{
		/* Se não pegou IP ainda conectando */
		if(aux_WF_GetIP() != Result_Ok)
		{
			aux_USART0_puts("%s=%d\r\n", "WF_CST", Status_ConnectionConnecting);
		}
		/* Se ja pegou IP */
		else
		{
			aux_USART0_puts("%s=%d\r\n", "WF_CST", Status_ConnectionConnected);
			aux_SetConnectionState(Status_ConnectionConnected);
		}
	}
	/* Se em modo SoftAP */
	else if(aux_GetConnectionState() == Status_SoftAP)
	{
		/* Se não pegou IP ainda não levantou AP */
		if(aux_WF_GetIP() != Result_Ok)
		{
			aux_USART0_puts("%s=%d\r\n", "WF_CST", Status_ConnectionConnecting);
		}
		/* Se ja pegou IP */
		else
		{
			aux_USART0_puts("%s=%d\r\n", "WF_CST", Status_SoftAP);
		}
	}
	/* Se ja conectou mas perdeu conexão */
	else if(aux_WF_GetIP() != Result_Ok)
	{
		aux_USART0_puts("%s=%d\r\n", "WF_CST", Status_ConnectionDisconnected);
	}
	/* Se ja conectou e continua conectado */
	else
	{
		aux_USART0_puts("%s=%d\r\n", "WF_CST", Status_ConnectionConnected);
	}

	aux_SetBusy(FALSE);
}

/**
  * @}
  */

/**
  * @}
  */


